package client;

import java.rmi.RemoteException;
import java.util.List;

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import client.gui.SearchSong;
import dto.MemberDTO;
import dto.RecomendationDTO;
import dto.SongDTO;
import dto.SongInfoDTO;

public class ClientController {
	private static ClientController instance;
	private RMIServiceLocator rsl;
	
	public ClientController(String[] args) throws RemoteException {
		rsl = new RMIServiceLocator();
		rsl.setService(args);
		try {
			for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (Exception e) {
		}
		new SearchSong(this,"","");
	}
	public static synchronized ClientController getInstance (String [] args) throws RemoteException{
		if (instance == null){
			instance = new ClientController(args);
		}
		return instance;
	}
	
	public List<RecomendationDTO> showRecomendationList() {
		//No implementada
		return null;
	}
	
	public List<SongInfoDTO> getFavouriteList() throws RemoteException {
		return rsl.getService().getFavouriteList();
		
	}
	
	public List<SongInfoDTO> getPermanentList() {
		//No implementada
		return null;
	}
	
	public void addFavourite(SongInfoDTO song) throws RemoteException {
		rsl.getService().addFavourite(song);
	}
	
	public void addPermanent(SongInfoDTO song) {
		//No implementada
	}
	
	public void recomendSong(SongInfoDTO song, MemberDTO targetMember) {
		//No implementada
	}
	
	public String playRecomendation() {
		//No implementada
		return null;
	}
	
	public SongDTO play(SongInfoDTO sid, MemberDTO md) throws RemoteException {
		//TODO revisar a ver si está bien
		return rsl.getService().play(sid, md);
	}
	
	public List<SongInfoDTO> searchArtist(String artist) throws RemoteException {
		return rsl.getService().searchArtist(artist);
	}
	
	public static void main (String [] args) throws RemoteException{
		ClientController.getInstance(args);
	}
}
